/*
 * @Author: zhangxuanjiu
 * @Date: 2017-08-10 14:38:22
 * @Last Modified by: zhangxuanjiu
 * @Last Modified time: 2017-10-20 16:33:54
 */

const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
  resolve: {
    modules: [
      path.join(__dirname, 'src-v2'),
      'node_modules'
    ],
    extensions: ['.js', '.jsx', '.css', '.less', '.vue'],
    alias: {
      'vue$': 'vue/dist/vue.js'
    }
  },
  context: path.join(__dirname, 'src-v2'),
  entry: {
    app: ['whatwg-fetch', './index.js'],
    agentApply: ['whatwg-fetch', './agentApply/index.js']
  },
  output: {
    path: path.join(__dirname, 'build-v2'),
    filename: '[name].[hash:5].js',
    publicPath: './',
    chunkFilename: '[name].js?[hash:8]'
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      mangle: true,
      compress: {
        warnings: false, // 禁止生成warning
        drop_debugger: true,
        drop_console: false
      }
    }),
    new htmlWebpackPlugin({
      template: './home_page.html', 
      filename: './home_page.html', 
      chunks: ['app'],
      showErrors: true,
      inject: 'body',
      hash: true
    }),
    new htmlWebpackPlugin({
      template: './agentApply/agentApply.html', 
      filename: './agentApply.html', 
      chunks: ['agentApply'],
      showErrors: true,
      inject: 'body',
      hash: true
    })
  ],
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.css/,
        use: ['style-loader', 'css-loader', 'postcss-loader']
      },
      {
        test: /\.less/,
        use: ['style-loader', 'css-loader', 'autoprefixer-loader', 'less-loader']
      },
      {
        test: /\.(png|jpg|gif|svg|eot|svg|ttf|woff|woff2)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]'
        }
      }
    ],

  }
}